$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/bsysuserweekscore/getList',
        datatype: "json",
        colModel: [
            {label: 'id', name: 'id', index: 'id', align: "center", width: 60, key: true, hidden: true},
            {label: '用户ID', name: 'userId', index: 'user_id', align: "center", width: 60},
            {label: '用户名称', name: 'userName', index: 'user_name', align: "center", width: 100},
            {label: '跟进次数', name: 'followCount', index: 'follow_count', align: "center", width: 80},
            {label: '成交订单数', name: 'dealedCount', index: 'follow_count', align: "center", width: 80},
            {label: '成交订单积分', name: 'dealedScore', index: 'dealed_score', align: "center", width: 80},
            {label: '总积分', name: 'totalScore', index: 'total_score', align: "center", width: 60},
            {label: '期数', name: 'period', index: 'period', align: "center", width: 60},
            {label: '开始时间', name: 'beginTime', index: 'begin_time', align: "center", width: 100},
            {label: '结束时间', name: 'endTime', index: 'end_time', align: "center", width: 100},
            {label: '创建时间', name: 'createTime', index: 'create_time', align: "center", width: 100},
            {label: '修改时间', name: 'modifyTime', index: 'modify_time', align: "center", width: 100},
        ],
        viewrecords: true,
        height: 520,
        rowNum: 15,
        rowList: [15, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        postData:{'userId':vm.q.userId,'userName':vm.q.userName,'period':vm.q.period},
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });

    $.ajax({
        type: "GET",
        url: baseURL + "sys/bsysuserweekscore/periodList",
        aysnc: false,
        contentType: "application/json;charset=utf-8",
        success: function (r) {
            if (r.code == 0) {
                $("#periodList").append("<option value=''>全部</option>");
                for(let index in r.periodList) {
                    let period = r.periodList[index].period;
                    let detail = r.periodList[index].beginMonth + "月" + r.periodList[index].beginDay + "日 - " + r.periodList[index].endMonth + "月" + r.periodList[index].endDay + "日";
                    $("#periodList").append("<option value='"+period+"'>第"+period+"期("+detail+")</option>");
                }
            }
        }
    });
})

var vm = new Vue({
    el:'#rrapp',
    data: {
       q: {
           userId: null,
           userName: null,
           period: ''
       },
        showList: true
    },
    methods: {
        query: function () {
            vm.reload();
        },
        reload: function (event) {
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData:{'userId':vm.q.userId,'userName':vm.q.userName,'period':vm.q.period},
                page: page
            }).trigger("reloadGrid");
        },
    }
});